package com.org.controller.pc;

import com.org.DTO.PageDTO;
import com.org.entity.PlaceDictionarie;
import com.org.result.Result;
import com.org.service.DictionarieService;
import com.org.vo.PageResult;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

/**
 * 字典控制器
 */

@RestController
@RequestMapping("/pc/admin")
@Slf4j
@RequiredArgsConstructor
public class DictionarieController {

    private final DictionarieService dictionarieService;

    /**
     * 查询所有地点字典
     * @param pageDTO
     * @return
     */
    @GetMapping("/findAllPlace")
    public Result<PageResult> findAllPlace(PageDTO pageDTO) {
        return Result.success(dictionarieService.findAllPlace(pageDTO));
    }

    /**
     * 添加地点字典
     * @param place
     * @return
     */
    @PostMapping("/addPlace")
    public Result<String> addPlace(@RequestBody PlaceDictionarie place) {
        log.info("添加的地点：{}", place);
        dictionarieService.addPlace(place);
        return Result.success("添加地点成功");
    }

    /**
     * 修改地点字典
     * @param place
     * @return
     */
    @PutMapping("/updatePlace")
    public Result<String> updatePlace(@RequestBody PlaceDictionarie place) {
        log.info("修改的地点ID：{}", place.getId());
        dictionarieService.updatePlace(place);
        return Result.success("修改地点成功");
    }

    /**
     * 删除地点字典
     * @param id
     * @return
     */
    @DeleteMapping("/deletePlace/{id}")
    public Result<String> deletePlace(@PathVariable("id") Long id) {
        log.info("删除的地点ID：{}", id);
        dictionarieService.deletePlace(id);
        return Result.success("删除地点成功");
    }

}
